<?php

/**
 * @author chenxuezhi11
 * @copyright 2016
 */

namespace Email\Controller;
use Common\Controller\ApiController;
use Org\Util\Xhprof;


class TestController extends ApiController {
    

    public function test2() {
        echo phpinfo();
        exit;
        $redis = REDIS('activity');
        $redis->select(3);
        //$data = $redis->hGetAll('monolys');
        $incr = $this->countLog('sdgames','sdgames:test4',3);  // 记录游客用户(相当于总用户)

        $list = $redis->hget('sdgames',2);
        $info = json_decode($list,true);
        $info['sdgames:test4'] = $incr;
   
        $redis->hset('sdgames',2,json_encode($info));

    }

    public function bar($x) {
        if ($x > 0) {
            $this->bar($x - 1);
        }
    }

    public function foo() {
      for ($idx = 0; $idx < 5; $idx++) {
        $this->bar($idx);
        $x = strlen("abc");
      }
    }

    public function index()
    {
        ini_set('display_errors', 1);
        error_reporting(E_ALL);

        abc();
       // start profiling
        xhprof_enable();

        // run program
        $this->foo();

        // stop profiler
        $xhprof_data = xhprof_disable();

        $xhprof_runs = new Xhprof();
     
        // save the run under a namespace "xhprof_foo"
        $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");

        echo "---------------\n".
             "Assuming you have set up the http based UI for \n".
             "XHProf at some address, you can view run at \n".
             "http://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_foo\n".
             "---------------\n";
    }



    public function test() {
        $time = date('Y-m-d');
        $auth_user = M('sdxxl_game.users')->where("status = 2 AND left(create_time,10) = '{$time}' ")->count();
        
        echo M('sdxxl_game.users')->getlastsql();
        exit;

        $a = '130704157874875870000000000000000000000000';
        $b = $this->money($a);
        print_r($b);
    }

    function money($money) {
        $arr = array('','K','M','B','T','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP');
        $len = strlen($money);
        $d =  ceil( $len / 3);

        $unit = $arr[$d -1];  // 计量单位
        
        $num1 = intval(substr($money,0,$len-(3*($d-1))));

        $num2 = substr($money,strlen($num1),$len-(3*($d-2)));

        $coin = $num1.'.'.$num2;

        $res = sprintf("%.2f", $coin);

        return $res.$unit;
    }

    //
    public function get_memory(){

    }
}